<?php 

include '../conf/db-config.php';

include_once '../conf/error.php';
include_once '../submitemail.php';
include_once '../clsFetchData.php';
$id = $_REQUEST['id'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state']; 

/*
 * UNIQUE ID CREATION: & APPROVAL
 */

$sqlGetBusinessTitleandCity = "SELECT count(*) as count, unique_id FROM tbl_globaltodo_listings WHERE city='$city' 
							   AND business_title IN (
							   SELECT business_title FROM tbl_globaltodo_listings
							   WHERE id=$id
							   ) AND id NOT IN ($id) AND is_approved='y'";

$run = mysql_query($sqlGetBusinessTitleandCity);
while ($data=mysql_fetch_array($run))
{
	$count = $data['count'];
	$unique_id  = $data['unique_id'];
}


if($count>0 && strlen($unique_id)>0)
{
	$uniqueId = $unique_id;
}
else
{
	$eightDigitId = sprintf("%08d", $id);
	$uniqueId = strtoupper($city).strtoupper($state).$eightDigitId;
}

$sql ="UPDATE tbl_globaltodo_listings SET unique_id='$uniqueId', is_approved='y' WHERE id=".$id;
if(mysql_query("UPDATE tbl_globaltodo_listings SET unique_id='$uniqueId', is_approved='y' WHERE id=".$id))
{
	$admin_mail_id = "listings@globaltodo.com";
	
	$objFetchData = new clsFetchData();
	$arrDataToShow = $objFetchData->getAllDataForId($id);
					
	$category = stripslashes($arrDataToShow['theme']);
	$businessTitle = stripslashes($arrDataToShow['business_title']);
	$business_desc = stripslashes($arrDataToShow['business_desc']);	
	$business_summary = stripslashes($arrDataToShow['business_summary']);					
	$phone_number = $arrDataToShow['phone_number'];
	$city = $arrDataToShow['city'];
	$state = $arrDataToShow['state'];
	$zipCode = $arrDataToShow['zipcode'];
	$streetAddress = stripslashes($arrDataToShow['street_address']);
	$emailId = $arrDataToShow['email_address'];
	$websiteAddress = $arrDataToShow['website_address'];
	$audioUrl = $arrDataToShow['audio_url'];
	$videoUrl = $arrDataToShow['video_url'];
	$salesRepresentatives = stripslashes($arrDataToShow['sales_rep']);
	$tollfree = $arrDataToShow['tollfree_number'];
	$fax = $arrDataToShow['fax_number'];
	$logo = $arrDataToShow['business_logo'];

	
	$message="";
	
	$message .="<h3>Following Listing has been approved.</h3>";
	$message .="<br /><br />";
	$message .="<b>Business Title :</b> $businessTitle"; 
	if(strlen($category)>0)
	{
		$message .="<br />";
		$message .="<b>Category :</b> $category";
	}
	if(strlen($business_desc)>0)
	{
		$message .="<br />";
		$message .="<b>Business Desc :</b> $business_desc";
	}
	if(strlen($business_summary)>0)
	{
		$message .="<br />";
		$message .="<b>Business Summary :</b> $business_summary";
	}
	if(strlen($phone_number)>0)
	{
		$message .="<br />";
		$message .="<b>Phone Number :</b> $phone_number";
	}
	if(strlen($tollfree)>0)
	{
		$message .="<br />";
		$message .="<b>Toll Free Number:</b> $tollfree";
	}
	if(strlen($fax)>0)
	{
		$message .="<br />";
		$message .="<b>Fax Number:</b> $fax";
	}
	if(strlen($streetAddress)>0)
	{
		$message .="<br />";
		$message .="<b>Street Address :</b> $streetAddress";
	}
	if(strlen($city)>0)
	{
		$message .="<br />";
		$message .="<b>City :</b> $city";
	}
	if(strlen($state)>0)
	{
		$message .="<br />";
		$message .="<b>State :</b> $state";
	}
	if(strlen($zipCode)>0)
	{
		$message .="<br />";
		$message .="<b>Zipcode :</b> $zipCode";
	}
	if(strlen($emailId)>0)
	{
		$message .="<br />";
		$message .="<b>Email Id:</b> $emailId";
	}
	if(strlen($websiteAddress)>0)
	{
		$message .="<br />";
		$message .="<b>Website Address :</b> <a href='$websiteAddress' >$websiteAddress</a>";
	}
	if(strlen($audioUrl)>0)
	{
		$message .="<br />";
		$message .="<b>Audio URL:</b> $audioUrl";
	}
	if(strlen($videoUrl)>0)
	{
		$message .="<br />";
		$message .="<b>Video URL:</b> $videoUrl";
	}
	if(strlen($salesRepresentatives)>0)
	{
		$message .="<br />";
		$message .="<b>Sales Representative Name :</b> $salesRepresentatives";
	}
	if(strlen($logo)>0)
	{
		$finalLogo = "http://www.globaltodo.com/xmlcontact/$logo";
		$message .="<br />";
		$message .="<b>Logo :</b><br /> <img src=\"$finalLogo\" width='150' height='100' />";
	}
	
	
	//file_put_contents("C:\\messgae.txt",$message);
	
	$subjectLine = $city." city: New Listing has been Approved .";
	
  	GENERATE_SMTP_MAIL($admin_mail_id,$admin_mail_id,"GlobalToDo",'','',$subjectLine,$message,'');
	//file_put_contents("C:\\messgae1.txt",$newMsg);
  	echo 1;
}
else
{
	echo 0;
}



?>